<template>
  <div>
    <nav-bar>
      <div slot="left" class="back" @click="backClick">
        <img src="~assets/img/common/back.svg" alt="" />
      </div>
      <div slot="center" class="navbar">
        <div
          class="navbar-item"
          v-for="(item, index) in titles"
          :key="index"
          :class="{ active: index === currentindex }"
          @click="titleClick(index)"
        >
          {{ item }}
        </div>
      </div>
    </nav-bar>
  </div>
</template>

<script>
import NavBar from "components/common/navbar/NavBar";

export default {
  name: "DetailNavBar",
  components: {
    // 导航栏
    NavBar,
  },
  data() {
    return {
      titles: ["商品", "参数", "评论", "推荐"],
      currentindex: 0,
    };
  },
  methods: {
    titleClick(index) {
      this.currentindex = index;
      this.$emit("titleClick", index);
    },
    backClick() {
      // this.$router.go(-1); // 也可以
      this.$router.back();
    },
  },
};
</script>

<style scoped>
.navbar {
  display: flex;
  font-size: 14px;
}
.navbar-item {
  flex: 1;
}
.active {
  color: var(--color-high-text);
  font-size: 16px;
}

.back img {
  margin-top: 12px;
}
</style>